const math = require('../../../utils/math.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state: 1,
    money: 0,
    price: 0,
    orderNumber: "",
    plateNumber: "",
    couponnum: 0,
    serviceCardnum: 0
  },
  onLoad: function(options) {
    if (options.text == "充值") {
      this.setData({
        state: 2,
        money: options.money,
        price: options.price,
        orderNumber: options.orderNumber,
      })
    }
    if (options.text == "消费") {
      this.setData({
        state: 1,
        money: options.money,
        orderNumber:options.orderNumber,
        plateNumber: options.plateNumber
      })
      console.log(options,"options")
      if(options.couponnum!=="0"){
        // wx.showToast({
        //   title: '恭喜你获得' + options.couponnum + '张优惠券' + options.serviceCardnum + '张服务卡',
        //   icon: 'none',
        //   duration: 3000
        // })
        this.setData({
          couponnum:options.couponnum,
          serviceCardnum:options.serviceCardnum
        })
      }
    }
    if (options.data) {
      let data = JSON.parse(options.data)
      if (data.type == 2) {
        this.setData({
          state: 3,
          money: math.divide(data.order.payAmount,100),
          orderNumber: data.order.orderNumber,
          plateNumber: math.divide(data.order.orderAmount,100)
        })
      }
      if(data.type==1){
        this.setData({
          state: 2,
          money: math.divide(data.rechargerOrder.amount, 100),
          price: math.divide(data.rechargerOrder.redPackedAmount, 100),
          orderNumber: data.rechargerOrder.rechargeNumber,
        })
      }
    }

  },
  //跳转到订单页面
  goDetails() {
    wx.navigateTo({
      url: '/pages/myorder/success/success?orderNumber=' + this.data.orderNumber
    })
  },
  goOrderRecharge() {
    wx.navigateTo({
      url: '/pages/orderList/rechargeOrderInfo/rechargeOrderInfo?orderNumber=' + this.data.orderNumber,
    })
  },
  goOrderRecharge2() {
    wx.navigateTo({
      url: '/pages/orderList/consumptionOrderInfo/consumptionOrderInfo?orderNumber=' + this.data.orderNumber,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() { //如果页面被卸载时被执行
    if (this.data.state == 1) {
      wx.switchTab({
        url: '/pages/index/index',
      })
    } else {
      wx.switchTab({
        url: '/pages/member/member'
      })
    }
  },
  // 在订单详情 
  go_home() {
    wx.navigateTo({
      url: '/pages/public/pages/myorderDetail/myorderDetail?state=1&data=' + this.data.orderNumber,
    })
  },
})